import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/education/custom_new_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/application/education/train_plan/get_education_plan_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/education/train_program/train_program_controller.dart';

///培训计划
class TrainProgramView extends StatelessWidget {
  TrainProgramView({super.key}){
    Get.lazyPut(TrainProgramController.new);
  }
  @override
  Widget build(BuildContext context) {
    final TrainProgramController controller = Get.find<TrainProgramController>();
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            key: controller.riskRightScaffoldKey,
            body: Container(
              color: AppColors.bg_color_grey,
              padding: EdgeInsets.only(top: 12.w, right: 14.w, left: 14.w),
              child: Column(
                children: [
                  Row(
                    children: [
                      Expanded(
                        child: _getSearchEnterWidget(controller),
                      ),
                      AppGaps.hGap8,
                      _screen(controller),
                      AppGaps.vGap10,
                    ],
                  ),
                  AppGaps.vGap12,
                  Expanded(
                      child: CustomEasyRefreshList<GetEducationPlanEntity>(
                    key: controller.globalKey,
                    dataLoad: controller.getEducationPlan,
                    itemBuilder: (item, index) {
                      return CustomNewTitleChartPage(
                        title: '${item.planName}',
                        titleRightWidget: Container(
                          width: 52.w,
                          height: 18.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              color: _strStatusColors(item.status),
                              borderRadius: const BorderRadius.only(
                                topLeft: Radius.circular(10),
                                topRight: Radius.circular(10),
                                bottomRight: Radius.circular(10),
                              )),
                          child: Text(
                            _strStatus(item.status),
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 10.sp,
                              fontWeight: FontWeight.w400,
                            ),
                          ),
                        ),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            _rowData('培训类型：', item.trainingTypeName ?? '', alignment: Alignment.centerRight),
                            AppGaps.vGap12, //培训途径 1:线上 2:线下
                            _rowData('培训途径：', item.trainingChannels == '1' ? '线上' : '线下', alignment: Alignment.centerRight),
                            AppGaps.vGap12,
                            _rowData('培训级别：', item.trainingLevelName ?? '', alignment: Alignment.centerRight),
                            AppGaps.vGap12,
                            _rowData('培训时间：', item.startTime ?? '', alignment: Alignment.centerRight),
                          ],
                        ),
                      ).click(() {
                        controller.onClickButtonPressed(item);
                      });
                    },
                  )),
                ],
              ),
            ), // 右侧筛选栏
            // endDrawer:  CustomEndDrawer(
            //   centerContext: Column(
            //     children: [
            //       _selectType('状态', controller.statusBack,controller),
            //       _selectType('培训类型', controller.trainingTypeBack,controller),
            //       _selectType('培训途径', controller.trainingChannelsBack,controller),
            //       _selectType('培训级别', controller.trainingLevelBack,controller),
            //       _alignTitle('培训时间'),
            //       AppGaps.vGap16,
            //       CustomSelectTimePeriod(
            //         startTime: controller.startDate,
            //         endTime: controller.endDate,
            //         onConfirm: (start, end) {
            //           controller.startDate = start;
            //           controller.endDate = end;
            //         },
            //         showBorder: true,
            //         iconCalendar: AppImages.icon__screen_clock,
            //       ),
            //     ],
            //   ),
            //   reset: controller.reset,
            //   confirm: controller.confirm,
            // ),
          );
        });
  }

  //搜索框
  Widget _getSearchEnterWidget(TrainProgramController controller) {
    return Container(
        height: 38.w,
        padding: EdgeInsets.symmetric(horizontal: 12.w),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            color: Colors.white, border: Border.all(color: const Color(0xffF0F0F0), width: 1.w), borderRadius: BorderRadius.all(Radius.circular(8.w))),
        child: Row(
          children: [
            SvgPicture.asset(
              AppImages.icon_search,
              width: 16.w,
            ),
            Expanded(
                child: TextField(
                    keyboardType: TextInputType.text,
                    textInputAction: TextInputAction.done,
                    onChanged: (value) {
                      controller.searchX = value;
                      controller.refreshPage();
                    },
                    style: TextStyle(color: const Color(0xff222222), fontWeight: FontWeight.w400, fontSize: 14.sp),
                    decoration: InputDecoration(
                      counterText: '',
                      //防止适配不居中
                      isCollapsed: true,
                      border: const OutlineInputBorder(borderSide: BorderSide.none),
                      contentPadding: EdgeInsets.only(left: 8.w),
                      hintText: '请输入调研名称搜索',
                      hintStyle: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w400, color: const Color(0xffA0A7B5)),
                    )))
          ],
        ));
  }

  ///筛选
  Widget _screen(TrainProgramController controller) {
    return Container(
      width: 38.w,
      height: 38.w,
      alignment: Alignment.center,
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: SvgPicture.asset(
        AppImages.icon_search_screen,
        width: 16.w,
      ),
    ).click(controller.onFilterButtonPressed);
  }

  Widget _rowData(String name, String value, {Alignment alignment = Alignment.centerLeft}) {
    return Row(
      children: [
        Text(
          name,
          style: TextStyle(
            color: const Color(0xFFA5A6B5),
            fontWeight: FontWeight.w400,
            fontSize: 13.sp,
          ),
        ),
        Expanded(
          child: Align(
            alignment: alignment,
            child: Text(
              value,
              style: TextStyle(
                color: const Color(0xFF495061),
                fontSize: 12.sp,
                fontWeight: FontWeight.w400,
              ),
            ),
          ),
        )
      ],
    );
  }

  //	审核状态 0:待提交 1:进行中 2:已结束 //0：待发起 1：待审批 2：审批中 3：通过 4：驳回
  String _strStatus(String? status) {
    switch (status) {
      case '0':
        return '待发起';
      case '1':
        return '待审批';
      case '2':
        return '审批中';
      case '3':
        return '通过';
      case '4':
        return '驳回';
      default:
        return '';
    }
  }

  //	审核状态 0:待提交 1:进行中 2:已结束//0：待发起 1：待审批 2：审批中 3：通过 4：驳回
  Color _strStatusColors(String? statusColors) {
    switch (statusColors) {
      case '0':
        return const Color(0xFFFC9900);
      case '1':
        return const Color(0xFFA5A9C8);
      case '2':
        return const Color(0xFFA5A9C8);
      case '3':
        return const Color(0xFF00CE78);
      case '4':
        return const Color(0xFFDE0F0F);
      default:
        return const Color(0xFFA5A9C8);
    }
  }

}

